package pl.softech.gpw.dao;

import java.util.LinkedList;
import java.util.List;

public class FileDownloadMonitor {

	public interface FileDownloadListener {
		
		public void actionPerformed(FileDownloadEvent event);
		
	}
	
	public static class FileDownloadEvent {
		
		public enum Type { MESSAGE, BYTES_RECIEVED, START};
		
		public String message;
		public int bytes;
		public long size;
		public Type type;
		public FileDownloadEvent(String message) {
			this.message = message;
			this.type = Type.MESSAGE;
		}
		public FileDownloadEvent(int bytes) {
			this.bytes = bytes;
			this.type = Type.BYTES_RECIEVED;
		}
		public FileDownloadEvent(String message, Type type, long size) {
			this.message = message;
			this.type = type;
			this.size = size;
		}
	}
	
	
	private final List<FileDownloadListener> listeners;

	public FileDownloadMonitor() {
		this.listeners = new LinkedList<FileDownloadListener>();
	}
	
	public void fireEvent(FileDownloadEvent event) {
		
		for(FileDownloadListener l : listeners) {
			l.actionPerformed(event);
		}
		
	}
	
	public void add(FileDownloadListener l) {
		listeners.add(l);
	}
	
	public void remove(FileDownloadListener l) {
		listeners.remove(l);
	}
	
}
